package com.device.service;

import com.device.config.WebSocketConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
import java.util.Map;

@Service
public class WebSocketService {

    private static final Logger logger = LoggerFactory.getLogger(WebSocketService.class);


    @Autowired
    private SimpMessagingTemplate messagingTemplate;
    
    @Autowired
    private ObjectMapper objectMapper;
    
    public void sendConfigUpdate(String deviceImei, Map<String, Object> configData) {
        try {
            String jsonMessage = objectMapper.writeValueAsString(configData);
            messagingTemplate.convertAndSend("/topic/device/" + deviceImei, jsonMessage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

} 